#!/bin/bash
OK=0
WARN=1
CRITICAL=2
UNKNOWN=3
PATH="/bin:/sbin:/usr/bin:/usr/sbin"

Ok_name=''
Fail_name=''
Judge=0
TTimeout=25
HName=`/bin/hostname -s`

function timeout_df() {
		#echo $choice start
                #/usr/bin/timeout 1 /bin/strace touch /$2 1>/dev/null 2>&1
                /usr/bin/timeout $TTimeout /bin/strace /bin/lfs df -h /$1  1>/dev/null 2>&1
                #/usr/bin/timeout $TTimeout /bin/strace /usr/bin/df -h /$1  1>/dev/null 2>&1
                if [ $? != 0  ]
                then
                        Judge=1
                        Fail_name="${Fail_name} ${choice}"
		else
			Ok_name="${Ok_name} ${choice}"
                fi
		#echo $choice end
}


function timeout_df2() {
                #echo $choice start
                #/usr/bin/timeout 1 /bin/strace touch /$2 1>/dev/null 2>&1
                /usr/bin/timeout $TTimeout /bin/strace df -h /$1  1>/dev/null 2>&1
                if [ $? != 0  ]
                then
                        Judge=1
                        Fail_name="${Fail_name} ${choice}"
                else
                        Ok_name="${Ok_name} ${choice}"
                fi
                #echo $choice end
}



if [ -e /etc/init.d/lustre ]
then

#Lmount=`cat /etc/init.d/lustre  |grep "nms check"|awk -F : '{print $2}'`
Lmount="sdcfs"
#for choice in besfs bes3fs publicfs besfs2 dybfs scratchfs workfs cefs             
        ###
for choice in $Lmount
do
	case $choice in

        dyfs2)
                timeout_df  "dybfs2"   # /etc/init.d/lustre not right
                ;;

        workfs2)
                timeout_df  "$choice" #can not ro because login nodes are rw
                ;;
        gecamfs)
                timeout_df2  "$choice" # have specail right
                ;;
        *)
                timeout_df  "$choice"
                ;;


	esac

done

if [ $Judge -eq 1 ]
then
	echo "$Fail_name  df_timeout after $TTimeout second wrong"
	exit $CRITICAL
else
	echo " $Ok_name  df_time are in $TTimeout second OK "
	exit $OK
fi

else
	echo "can not find file /etc/init.d/lustre"
	exit $CRITICAL
fi
